package com.csun.cmny.provider.config;

import com.csun.cmny.provider.task.AppClockQuartz;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2020-04-20 11:44
 * @Description:
 */
@Slf4j
@Configuration
public class CmnyQuartzConfig {

    @Bean
    public JobDetail appClockQuartzDetail() {
        return JobBuilder.newJob(AppClockQuartz.class).withIdentity("appClockQuartz").storeDurably().build();
    }

    @Bean
    public Trigger appClockQuartzTrigger() {
//        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
//                .withIntervalInSeconds(1)  // 设置时间周期单位秒
//                .repeatForever();
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0 0/1 * * * ?");
        return TriggerBuilder.newTrigger().forJob(appClockQuartzDetail())
                .withIdentity("appClockQuartz")
                .withSchedule(cronScheduleBuilder)
                .build();
    }

}
